<?php

$domain = (isset($_REQUEST['domain'])) ? $_REQUEST['domain'] : false;

?>

<div class="moduleTopNav clearfix">
	<div class="fl-l">
		<?php $module->printAddLink($lang->get('add-languages')); ?>
	</div>
	<div class="fl-r">
		<?php
		/*<input type="text" name="filter" class="fld" /> <input type="submit" value="Filter by keyword" />*/
		?>
	</div>
</div>

<table class="datatable">
	<thead>
		<tr>
			<td colspan="5">
				<?php
				$lang->put('select-domain');
				?>
				<select name="domain" onchange="window.location='<?php echo $cosa->system('base-url').'/?m='.$m.'&s='.$s.'&domain='; ?>'+this.value;">
					<option value=""> </option>
					<?php
					$domains = $module->getDomains();
					foreach($domains as $k => $v) {
						$selected = ($domain == $v['id']) ? ' selected="selected"' : '';
						?><option value="<?php echo stripslashes($v['id']); ?>"<?php echo $selected; ?>><?php echo stripslashes($v['name']); ?></option><?php
					}
					?>
				</select>
			</td>
		</tr>
		<?php if($domain) { ?>
		<tr>
			<td>&nbsp;</td>
			<td><?php $module->printSortLink($lang->get('language-name'), 'name'); ?></td>
			<td><?php $module->printSortLink($lang->get('language-short'), 'short'); ?></td>
			<td><?php $module->printSortLink($lang->get('active'), 'active'); ?></td>
			<td><?php $module->printSortLink($lang->get('default'), 'default'); ?></td>
		</tr>
		<?php } ?>
	</thead>
	<tbody>
		<?php
		
		$structure = array('name', 'active', 'default');
		$module->setStructure($structure);
		
		if($domain) {
			
			$res = $module->queryData("SELECT * FROM ".$db->table('languages')." WHERE domain_id='".$domain."'", false);
			
			if(mysql_num_rows($res)) {
				while($row = mysql_fetch_array($res)) {
					
					$data = array(	'id'				=> stripslashes($row['id'])
									,'name'				=> stripslashes($row['name'])
									,'short'			=> stripslashes($row['short'])
									,'active'			=> $bool[$row['active']]
									,'default'			=> $bool[$row['default']]
									);
					$module->printTableRow($data);
					
				}
			} else {
				$module->printEmptyTableRow($lang->get('no-items-found'));
			}
		
		} else {
			
			//$module->printEmptyTableRow($lang->get('select-domain'));
			
		}
		
		?>
	</tbody>
</table>
